<?php
/**
 * @file   common.php
 * @date   2017-12-13 15:22:57
 * @author huwhis<huuwhois>
 * @version   0.0.1
 */

// admin模块应用公共文件

/**2017-12-13
* get_adminuser_name()
* get_adminrole_name()
* get_category_name()
* get_permission_crtl()
* column方法得到以id为键,***_name为值的一维数组
* 12-15 逐步转移至对应的model
*/
function adminuser_name()
{
    return \app\admin\model\Adminuser::column('id,admin_name');
}
function get_adminuser_name($id = '')
{
    $data = adminuser_name();
    return $data[$id];
}


// function adminrole_name(){
//     return \app\admin\model\Adminrole::column('id,role_name');
// }
// function get_adminrole_name($id=''){
//     $data = model('Adminnrole')->adminrole_name();
//     return $data[$id];
// }

//栏目名name不分上下级
function category_name()
{
    return \app\admin\model\Category::column('id,category_name');
}
function get_category_name($id = '')
{
    $data = category_name();
    $data[0] = '无栏目';
    return $data[$id];
}
//分上下级
function category_name_tree()
{
    $data = \think\Db::table('dean_category')->field('id,pid,category_name')->select();
    $data = get_tree($data);
    return $data;
}

function localtion($ip)
{
    $url = 'http://api.map.baidu.com/location/211.94.114.193';
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $return_str = curl_exec($curl);
    curl_close($curl);

    return $return_str;
}
